package com.zhw.andfix.present;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.zhw.andfix.iview.IAppConfigInfoView;
import com.zhw.andfix.model.PatchBean;
import com.zhw.andfix.net.ApiService;

import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;

/**
 * AppConfigInfoPresent
 * Created by Administrator on 2018/3/20.
 */

public class AppConfigInfoPresent<V extends IAppConfigInfoView, LifecycleEvent> extends BasePresent<V, LifecycleEvent> {
    public AppConfigInfoPresent(V view, LifecycleProvider<LifecycleEvent> provider) {
        super(view, provider);
    }

    public void getAppConfigInfo(final boolean shwoLoading){
        composeApiFlowable(ApiService.getAppConfigInfoApi().getAppConfigInfo())
                .subscribe(new ApiSubscriber<PatchBean>() {
                    @Override
                    protected void onStart() {
                        super.onStart();
                        getV().showLoading(shwoLoading);
                    }

                    @Override
                    public void onNext(PatchBean appConfigInfo) {
//                        if (appConfigInfo != null){
//                            if (appConfigInfo.getPath_v().equals("1.2")){
//
//                            }
//                        }
                        getV().showAppConfigInfoResult(true, appConfigInfo.getCode(), appConfigInfo.getMessage(), appConfigInfo);
                    }

                    @Override
                    protected void onFail(NetError error) {
                        if (error != null){
                            getV().showResult(false, error.getType(), error.getMessage());
                        }
                    }

                    @Override
                    public void onComplete() {
                        getV().showLoading(false);
                    }
                });
    }
}
